package com.tsll.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tsll.dao.VerifyApplicationMapper;
import com.tsll.entity.Staff;
import com.tsll.entity.VerifyApplication;
import com.tsll.service.VerifyApplicationService;
import com.tsll.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;

/**
 * @author: Tian
 * @version: 1.0
 * @since: 1.0
 * @date: 2024/3/27/20:05
 */
@Service
public class VerifyApplicationServiceImpl implements VerifyApplicationService {

    @Autowired
    VerifyApplicationMapper verifyApplicationMapper;

    @Autowired
    HttpSession session;
    /**
     * 添加校验申请信息
     * @param
     * @return
     */
   public Integer insert(){
       Staff staff = (Staff) session.getAttribute("staff");
        VerifyApplication verifyApplication=new VerifyApplication(staff.getId(),0,new Date());
        verifyApplicationMapper.insert(verifyApplication);
        return verifyApplication.getId();
    }

    /**
     * 查询校验信息
     * @return
     */
    @Override
    public Result selectAll(Integer current,  Integer pageSize) {
        PageHelper.startPage(current,pageSize);
        List<VerifyApplication> verifyApplications = verifyApplicationMapper.selectAll();
        PageInfo<Object> pageInfo = new PageInfo<>(verifyApplications);
        return new Result(200,"校验信息查询成功",pageInfo);
    }


    /**
     *根据id修改审核状态
     * @param id
     * @return
     */
    @Override
    public int updateById(Integer id){
        Staff staff = (Staff) session.getAttribute("staff");
        VerifyApplication verifyApplication=new VerifyApplication();
        verifyApplication.setAuditTime(new Date());
        verifyApplication.setId(id);
        verifyApplication.setAuditorId(staff.getId());
        return verifyApplicationMapper.updateById(verifyApplication);
    }

    /**
     * 根据id修改驳回信息
     * @param rejection
     * @param id
     * @return
     */
    @Override
    public   Result updateRejectionById(String rejection, Integer id){
        Staff staff = (Staff) session.getAttribute("staff");
        VerifyApplication verifyApplication=new VerifyApplication();
        verifyApplication.setAuditTime(new Date());
        verifyApplication.setId(id);
        verifyApplication.setRejection(rejection);
        verifyApplication.setAuditorId(staff.getId());
        int i = verifyApplicationMapper.updateRejectionById(verifyApplication);
        return new Result(200,"驳回成功",i);
    }

    /**
     * 查询审核信息
     * @param current
     * @param pageSize
     * @return
     */
    @Override
    public Result selectAllInfo(Integer current, Integer pageSize) {
        PageHelper.startPage(current,pageSize);
        List<VerifyApplication> verifyApplications = verifyApplicationMapper.selectAllInfo();
        PageInfo<Object> pageInfo = new PageInfo<>(verifyApplications);
        return new Result(200,"校验信息查询成功",pageInfo);
    }


}
